1
単一プロンプトの枠を超えて:複雑なワークフローへの移行
AI010Lesson 4
00:00

「マジックプロンプト」の終焉

初期のLLM開発では、ユーザーはしばしばすべての指示、制約、データポイントを一つの巨大なプロンプトに「詰め込み」ようとしていました。直感的には自然ですが、このアプローチは過学習、高コストなトークン使用量を引き起こし、バグのデバッグがほぼ不可能になる「ブラックボックス」を作り出します。

業界はプロンプトチェイニングへとシフトしています。このモジュール式のアプローチでは、LLMを一つの過労した万能職人ではなく、専門的な作業者たちの連携として扱います。

なぜプロンプトをチェインするのか?

  • 信頼性:複雑なタスクを管理可能なサブタスクに分解することで、幻覚の発生率を大幅に低下させます。
  • 統合性:外部ツール(内部のJSONデータベースやAPIなど)からのデータをワークフロー途中で動的に注入できるようになります。
  • コスト効率:各ステップに必要なコンテキストのみを送信するため、トークンの消費を節約できます。
決定の原則:タスクの分解
一つのプロンプトは一つの特定の仕事を処理すべきです。もし一つのプロンプト命令で3つ以上の「そして次に」文を使っていると感じたら、それらを個別の呼び出しにチェインする時期です。
pipeline.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute pipeline.
>
Knowledge Check
Why is "Dynamic Context Loading" (fetching data mid-workflow) preferred over putting all possible information into a single system prompt?
It makes the model run faster on local hardware.
It prevents model confusion and reduces token costs by only providing necessary data.
It allows the model to ignore the system instructions.
Challenge: Designing a Safe Support Bot
Apply prompt chaining principles to a real-world scenario.
You are building a tech support bot. A user asks for the manual of a "X-2000 Laptop."

Your task is to define the logical sequence of prompts needed to verify the product exists in your database and ensure the final output doesn't contain prohibited safety violations.
Step 1
What should the first two actions in your pipeline be immediately after receiving the user's message?
Solution:
1. Input Moderation: Check if the prompt contains malicious injection attempts. Evaluate as $ (N/Y) $.
2. Entity Extraction: Use a specialized prompt to extract the product name ("X-2000 Laptop") from the raw text.
Step 2
Once the entity is extracted, how do you generate the final safe response?
Solution:
1. Database Lookup: Query the internal DB for "X-2000 Laptop" manual data.
2. Response Generation: Pass the user query AND the retrieved DB data to the LLM to draft an answer.
3. Output Moderation: Run a final check on the generated text to ensure no safety policies were violated before sending it to the user.